<?php
/*********************/
/*                   */
/*  Version : 5.1.0  */
/*  Author  : RM     */
/*  Comment : 071223 */
/*                   */
/*********************/

define( "JIEQI_MODULE_NAME", "system" );
require_once( "../global.php" );
include_once( JIEQI_ROOT_PATH."/class/power.php" );
$power_handler =& jieqipowerhandler::getinstance( "JieqiPowerHandler" );
$power_handler->getsavedvars( "system" );
jieqi_checkpower( $jieqiPower['system']['changegroup'], $jieqiUsersStatus, $jieqiUsersGroup, false, true );
jieqi_loadlang( "groups", JIEQI_MODULE_NAME );
if ( empty( $_REQUEST['uid'] ) )
{
		jieqi_printfail( LANG_NO_USER );
}
if ( $_REQUEST['gid'] == JIEQI_GROUP_ADMIN && $jieqiUsersGroup != JIEQI_GROUP_ADMIN )
{
		jieqi_printfail( $jieqiLang['system']['set_admin_deny'] );
}
include_once( JIEQI_ROOT_PATH."/class/users.php" );
$users_handler =& jieqiusershandler::getinstance( "JieqiUsersHandler" );
$user = $users_handler->get( $_REQUEST['uid'] );
if ( !is_object( $user ) )
{
		jieqi_printfail( LANG_NO_USER );
}
if ( $user->getvar( "groupid" ) == JIEQI_GROUP_ADMIN && $jieqiUsersGroup != JIEQI_GROUP_ADMIN )
{
		jieqi_printfail( $jieqiLang['system']['manage_admin_deny'] );
}
$chglog = array( );
$chginfo = "";
$chglog['groupid']['from'] = $user->getvar( "groupid" );
$chglog['groupid']['to'] = $_REQUEST['gid'];
$user->setvar( "groupid", $_REQUEST['gid'] );
$chginfo .= sprintf( $jieqiLang['system']['change_group_log'], $jieqiGroups[$chglog['groupid']['from']], $jieqiGroups[$chglog['groupid']['to']] );
if ( !$users_handler->insert( $user ) )
{
		jieqi_printfail( $jieqiLang['system']['change_group_failure'] );
}
else
{
		include_once( JIEQI_ROOT_PATH."/class/userlog.php" );
		$userlog_handler = jieqiuserloghandler::getinstance( "JieqiUserlogHandler" );
		$newlog = $userlog_handler->create( );
		$newlog->setvar( "siteid", JIEQI_SITE_ID );
		$newlog->setvar( "logtime", JIEQI_NOW_TIME );
		$newlog->setvar( "fromid", $_SESSION['jieqiUserId'] );
		$newlog->setvar( "fromname", $_SESSION['jieqiUserName'] );
		$newlog->setvar( "toid", $user->getvar( "uid", "n" ) );
		$newlog->setvar( "toname", $user->getvar( "uname", "n" ) );
		$newlog->setvar( "reason", $jieqiLang['system']['change_group_reason'] );
		$newlog->setvar( "chginfo", $chginfo );
		$newlog->setvar( "chglog", serialize( $chglog ) );
		$newlog->setvar( "isdel", "0" );
		$newlog->setvar( "userlog", "" );
		$userlog_handler->insert( $newlog );
		jieqi_msgwin( LANG_DO_SUCCESS, $jieqiLang['system']['change_group_success'] );
}
?>
